package com.spi.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Component
@Slf4j
public class ServerInfo {

    @Value("${server.port}")
    private String serverPort ;

    private String serverIp ;

    @Value("${rocketmq.consumer.group4.tag}")
    private String ymlAddress ;

    @PostConstruct
    public void init() {
        try {
            InetAddress address = InetAddress.getLocalHost();
            serverIp = address.getHostAddress();
            System.out.println("当前机器地址: " + getAddress());
            log.info("当前机器地址: " + getAddress());
            System.out.println("yml对应tag地址：" + ymlAddress);
            log.info("yml对应tag地址：" + ymlAddress);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

    public String getAddress() {
        return serverIp + ":" + serverPort;
    }
}
